package cn.lingyangwl.agile.infra.weixin.mp.manager;

import cn.lingyangwl.agile.infra.weixin.mp.constants.MpAutoReplyTypeEnum;
import cn.lingyangwl.agile.infra.weixin.mp.mapper.MpAutoReplyMapper;
import cn.lingyangwl.agile.infra.weixin.mp.model.entity.MpAutoReply;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 公众号消息自动回复
 *
 * @author shenguangyang
 */
@Slf4j
@Repository
public class MpAutoReplyManager extends ServiceImpl<MpAutoReplyMapper, MpAutoReply>
    implements IService<MpAutoReply> {

    public MpAutoReply getAutoReply(MpAutoReplyTypeEnum type) {
        return this.getOne(MpAutoReply.lqw().eq(MpAutoReply::getType, type.getType()));
    }

    public MpAutoReply getAutoReply(String requestMessageType) {
        LambdaQueryWrapper<MpAutoReply> lqw = MpAutoReply.lqw().eq(MpAutoReply::getRequestMessageType, requestMessageType);
        return this.getOne(lqw);
    }

    public MpAutoReply getAutoReplyByAccountIdAndKeyword(String requestKeyword) {
        LambdaQueryWrapper<MpAutoReply> lqw = MpAutoReply.lqw()
                .eq(MpAutoReply::getRequestKeyword, requestKeyword);
        return this.getOne(lqw);
    }

    public List<MpAutoReply> listByMpAppId(String mpAppId, MpAutoReplyTypeEnum type) {
        return this.list(MpAutoReply.lqw().eq(MpAutoReply::getMpAppId, mpAppId).eq(MpAutoReply::getType, type.getType()));
    }
}
